$(document).ready(function(){
	function bindResize(){
		var el = document.getElementById('drag')
		var els = el.style;
		var x;
		var lastLeft = 0;
		var minLeft = -9 , maxLeft = $('.score_slideBar').width() - 9;
		$(el).mousedown(function(e){
			var mouseStartX = e.layerX || e.offsetX;
			var offsetX = $('.score_slideBlock').offset().left;
			x = mouseStartX + offsetX;
			el.setCapture ? (
				el.setCapture(),
				el.onmousemove = function(ev){mouseMove(ev || event)},
				el.onmouseup = mouseUp
			):(
				$(document).bind("mousemove",mouseMove).bind("mouseup",mouseUp)
			)
			e.preventDefault()
		});
		function mouseMove(e){
			newLeft = lastLeft + e.clientX - x;
			if(newLeft < minLeft || newLeft > maxLeft)return;
			els.left = newLeft + 'px';
			
			$('.showHowMany').html(parseInt(newLeft) + 9);
			$('#eatHowMany').val(parseInt(newLeft) + 9);
		}
		function mouseUp(){
			el.releaseCapture ? (
				el.releaseCapture(),el.onmousemove = el.onmouseup = null
			):(
				$(document).unbind("mousemove", mouseMove).unbind("mouseup", mouseUp)
			)
			lastLeft = parseInt($('.score_slideBlock').css('left'));
		}
	}
	bindResize();
})